
export default {
    convertAxiosParams(data) {
        if (data == null || !data) {
            return null;
        }
        if (data instanceof URLSearchParams) {
            return data;
        }
        let params = new URLSearchParams();
        for (let i in data) {
            params.append(i, data[i])
        }
        return params;
    },
    convertAjaxParams(data) {
        if (data instanceof URLSearchParams) {
            let paramsStr = "{";
            for (let entry of data.entries()) {
                let key = entry[0];
                let value = entry[1];
                if (value == "null" || value == "true" || value == "false") {
                    paramsStr = paramsStr + "\"" + key + "\":" + value + ",";
                } else {
                    paramsStr = paramsStr + "\"" + key + "\":\"" + value + "\",";
                }
            }
            paramsStr = paramsStr.substr(0, paramsStr.length - 1);
            paramsStr += "}";
            return JSON.parse(paramsStr);
        }
        return data;
    },
    getParams(param) {
        let params = ''
        for (let i in param) {
            let p = param[i];
            if (!!p && p != null && p != '') {
                if (params == '') {
                    params = '?' + i + '=' + encodeURIComponent(p)
                } else {
                    params = params + '&' + i + '=' + encodeURIComponent(p)
                }
            }
        }
        // console.log("params:" + params)
        return params
    }
}
